import { deleteApi, getApi, postApi, putApi } from "@/axios/index";
import { mallStore } from "@/store/modules/mall";
import { TypeLogin } from "@/interface/login";

interface ApiParamsType {
    mall_id: number
    company_id: number
    system: number
}

function apiParams(): ApiParamsType {
    const { mallId, companyId, system } = mallStore();
    return { mall_id: mallId, company_id: companyId, system }
}

// 账号密码登陆
export const postApiLogin = (data: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}): Promise<TypeLogin.Response> => {
    return postApi('/api/login', data, config, header)
};

// 模拟登陆
export const postApiFakeLogin = (data: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}): Promise<TypeLogin.Response> => {
    return postApi('/api/fake-login', data, config, header)
};

// 用户信息
export const getApiUserInfo = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    return getApi('/api/user/info', params, config, header);
};

// 商场列表
export interface RestfulMallsRow {
    name: string,
    address: string,
    id: number
}

export interface PromiseRestfulMalls {
    code: number
    data: RestfulMallsRow[],
    msg: string
}

const v3Api = '/v3/api';
const restBV3Api = '/restb/v3/api';

export const getRestfulMalls = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}): Promise<PromiseRestfulMalls> => {
    return getApi('/restful/malls', {
        page: 1,
        per_page: 1000,
        ...params
    }, config, header)
};

// 商场 详情
export const getRestfulMallDetail = (config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/mall/${mall_id}`, {}, config, header)
};

export const getApiSystemElement = (params: ObjValueAny, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    return getApi(`/api/system/element`, params, config, header)
};

// 设置的商场 详情
export const getApiMallDetailSetting = (config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/api/mall/detail`, { mall_id }, config, header)
};

// 宙斯配置的商场详情
export const postV3ZeusMallConfig = (config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    const method = 'mall.config';
    return postApi(`${v3Api}?${method}`, {
        method,
        params: { mall_id },
    }, config, header);
};

// 配置商场详情
export const putRestfulMallConfig = (data: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return putApi(`/restful/mall/${mall_id}/config`, data, config, header)
};

// 路由列表
export const getApiSystemMenu = (config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id, system } = apiParams();
    const params = { mall_id, system };
    return getApi(`/api/system/menu`, params, config, header)
};

// 会员列表 集团
export const postV3ApiMemberList = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    const method = 'member.list';
    return postApi(`${v3Api}?${method}`, { method, params }, config, header);
};

// 付费会员 卡面
export const postV3PremiumList = (config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    const method = 'premium.list';
    let { company_id } = apiParams();
    return postApi(`${v3Api}?${method}`, {
        method,
        params: { company_id },
    }, config, header);
};

// 会员列表 商场
export const getRestfulMallMembers = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/mall/${mall_id}/members`, params, config, header)
};

// 会员详情 集团
export const postRestV3CompanyMemberDetail = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    const method = 'getCompanyMember';
    return postApi(`${restBV3Api}?${method}`, { method, params }, config, header);
};

// 会员详情 商场
export const getRestfulMallMemberDetail = (id: number = 0, params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/mall/${mall_id}/member/${id}`, params, config, header)
};

// 会员详情 消费记录 集团
export const postRestV3OrderList = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    const method = 'order.list';
    return postApi(`${restBV3Api}?${method}`, { method, params }, config, header);
};

// 会员详情 商场 消费记录
export const getRestfulMallMemberOrders = (id: number = 0, params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/mall/${mall_id}/member/${id}/orders`, params, config, header)
};

// 增加 消费记录
export const postRestfulMallOrder = (data: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return postApi(`/restful/mall/${mall_id}/order`, data, config, header)
}

// 会员详情 积分记录 集团
export const postRestV3PointList = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    const method = 'point.list';
    return postApi(`${restBV3Api}?${method}`, { method, params }, config, header);
};

// 会员详情 积分记录 商场
export const getRestfulMallMemberPoints = (id: number = 0, params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/mall/${mall_id}/member/${id}/points`, params, config, header)
};

// 积分变动来源
export const getRestfulPointsFilters = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/mall/${mall_id}/points/filters`, params, config, header)
}

// 小票审核 详情 审核次数统计
export const getRestfulMallPointsStats = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/mall/${mall_id}/points-stat`, params, config, header)
};

// 编辑会员详情
export const postV3UpdateMember = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    const method = 'updateMember';
    return postApi(`${v3Api}?${method}`, { method, params }, config, header);
};

// 新增会员
export const postV3StoreMember = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    const method = 'storeMember';
    return postApi(`${v3Api}?${method}`, { method, params }, config, header);
};

// 移入/移出 黑名单
export const postV3MemberUpdateStatus = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    const method = 'member.updateStatus';
    return postApi(`${v3Api}?${method}`, { method, params }, config, header);
};

// 地区列表
export const getRestfulLocations = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    return getApi(`/restful/locations`, params, config, header)
};

// 会员等级列表
export const getRestfulMallLevels = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/mall/${mall_id}/levels`, params, config, header)
};

// 人群包 列表
export const getRestfulMallMemberGroups = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/mall/${mall_id}/member-groups`, params, config, header)
};

// 上传人群包
export const postRestfulMallGrantMembersImport = (data: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return postApi(`/restful/mall/${mall_id}/grant/members/import`, data, config, header)
};

// 闪购优惠券 统计
export const getRestfulV2MallCouponStatusStats = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/v2/mall/${mall_id}/coupon-status-stats`, params, config, header)
};

// 闪购优惠券
export const getRestfulV2MallCoupons = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/v2/mall/${mall_id}/coupons`, params, config, header)
};

// 优惠券详情
export const getRestfulMallV2CouponDetail = (id: number, params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/v2/mall/${mall_id}/coupon/${id}`, params, config, header)
};

// 商场设置详情
export const getApiShopDetail = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    params.mall_id = mall_id;
    return getApi(`/api/shop/detail`, params, config, header)
};

// 会员 当前会员等级
export const postV3LevelProgress = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id, company_id } = apiParams();
    params.mall_id = mall_id;
    params.company_id = company_id;
    const method = 'level.progress';
    return postApi(`${v3Api}?${method}`, { method, params }, config, header);
};

// 会员详情 优惠券记录 集团
export const postRestV3CouponList = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    const method = 'getMemberCoupons';
    return postApi(`${restBV3Api}?${method}`, { method, params }, config, header);
};

// 会员详情 优惠券记录 商场
export const getRestfulMallMemberCoupons = (id: number = 0, params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/mall/${mall_id}/member/${id}/coupons`, params, config, header)
};

// 会员详情 会员信息变动记录
export const postV3MemberChangeLog = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    const method = 'member.changeLog';
    return postApi(`${restBV3Api}?${method}`, { method, params }, config, header);
};

// 优惠券 领用数据 明细
export const getRestfulMallCouponRecordDetail = (id: number, params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/mall/${mall_id}/coupon/${id}/record-detail`, params, config, header)
};

// 优惠券 领用数据趋势
export const getRestfulMallCouponRecord = (id: number, params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/mall/${mall_id}/coupon/${id}/record`, params, config, header)
};

// 优惠券 领用数据 结算 取消结算
export const postV3MemberCouponSettlement = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    params.mall_id = mall_id
    const method = 'memberCoupon.settlement';
    return postApi(`${v3Api}?${method}`, { method, params }, config, header);
};

// 优惠券 店铺核销统计
export const postV3CouponVerifyStatsByShop = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    params.mall_id = mall_id
    const method = 'coupon.verifyStatsByShop';
    return postApi(`${v3Api}?${method}`, { method, params }, config, header);
};

// 优惠券 领用数据 使用店铺
export const getRestfulMallCouponShops = (id: number, data: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/mall/${mall_id}/coupon/${id}/shops`, data, config, header)
};

// 修改优惠券库存
export const putRestfulMallCouponIncrease = (id: number, data: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return putApi(`/restful/v2/mall/${mall_id}/coupon/${id}/increase`, data, config, header)
};

// 复制微信外推广链接
export const postRestV3WechatShortUrl = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    const method = 'app.wechatShortUrl';
    let { mall_id } = apiParams();
    params.mall_id = mall_id;
    return postApi(`${restBV3Api}?${method}`, { method, params }, config, header);
};

// 行业
export const getRestfulMallIndustries = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/mall/${mall_id}/industries`, params, config, header)
};

// 获取店铺列表
export const getApiMajorList = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    params.mall_id = mall_id;
    return getApi(`/api/shop/major-list`, params, config, header)
};

// 活动列表
export const getMallMajorCampaigns = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/mall/${mall_id}/major-campaigns`, params, config, header)
};

// 新增活动
export const postMallCampaign = (data: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return postApi(`/restful/mall/${mall_id}/campaign`, data, config, header)
};

// 优惠券 上下架
export const putRestfulV2MallCouponStatus = (id: number, data: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return putApi(`/restful/v2/mall/${mall_id}/coupon/${id}/status`, data, config, header)
};

// 商品货架
export const getRestfulMallItems = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return getApi(`/restful/mall/${mall_id}/items`, params, config, header)
};

// 闪购商品 上下架
export const putRestfulMallItemStatus = (id: number, data: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return putApi(`/restful/mall/${mall_id}/item/${id}/status`, data, config, header)
};

// 拼团商品 上下架
export const putRestfulMallConglomerationStatus = (id: number, data: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    let { mall_id } = apiParams();
    return putApi(`/restful/mall/${mall_id}/conglomeration/${id}/status`, data, config, header)
};

// 下载中心
export const postRestV3DownloadStore = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    const method = 'download.store';
    return postApi(`${restBV3Api}?${method}`, { method, params }, config, header);
};

// 获取oss参数
export const postV3TokenStoreOss = (config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    const method = 'token.storeOss';
    return postApi(`${v3Api}?${method}`, { method }, config, header);
};

// 会员等级列表
export const postV3LevelWait = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    const method = 'level.wait';
    return postApi(`${v3Api}?${method}`, { method, params }, config, header);
};

// 更新会员等级
export const postV3LevelUpdate = (params: ObjValueAny = {}, config: ObjValueAny = {}, header: ObjValueAny = {}) => {
    const method = 'level.update';
    return postApi(`${v3Api}?${method}`, { method, params }, config, header);
};
